package test;

import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

/**
 * @Author GongXl
 * @Description 用户登录功能
 * @Date 006 15:18
 * @Param
 * @return
**/
@WebServlet(name="userRegServlet",urlPatterns={"/reg"})
public class UserRegServlet extends HttpServlet{
//    @Override
//    public void init(ServletConfig servletConfig) throws ServletException {
//        ServletContext servletContext = servletConfig.getServletContext();//application
//        //SpringMVC
//        String companyName = servletContext.getInitParameter("companyName");
//        System.out.println("UserServlet coname:"+companyName);
//        System.out.println(servletConfig.getServletName());
//        Enumeration<String> initParameterNames = servletConfig.getInitParameterNames();
//        while (initParameterNames.hasMoreElements()){
//            System.out.println("eeeeee:"+initParameterNames.nextElement());
//        }
//    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");//post
        resp.setContentType("text/html;charset=utf-8");
        ServletOutputStream outputStream = resp.getOutputStream();


        String k1 = (String)req.getAttribute("k1");

        outputStream.write(("reg服务"+k1).getBytes());
        outputStream.flush();
        outputStream.close();
        System.out.println("userservlet called end");
    }
}
